@extends("common.layout")

@section('title', '接口详情')

@section('head')
    @parent
    <style>
        .nav{
            width: 100%;
        }
        .api-info{
            box-shadow: 0 0 10px #94d5f1;
            border-radius: 5px;
        }
    </style>
@endsection

@section('body')
    <body class="pear-container" style="margin: 0">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基础信息</li>
                        <li>返回示例</li>
                        <li>在线测试</li>
                    </ul>

                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-card api-info">
                                <div class="layui-card-body">
                                    {{$row->summary}}
                                </div>
                            </div>

                            @if (!empty($row->headrs))
                                <div class="layui-card api-info">
                                    <div class="layui-card-header">头部</div>
                                    <div class="layui-card-body">
                                        <table class="layui-table">
                                            <colgroup>
                                                <col width="150">
                                                <col width="200">
                                                <col>
                                            </colgroup>
                                            <thead>
                                            <tr>
                                                <th>字段名</th>
                                                <th>类型</th>
                                                <th>是否必填</th>
                                                <th>描述</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr>
                                                <td>authcode</td>
                                                <td>string</td>
                                                <td>是</td>
                                                <td>固定格式code xxxxx</td>
                                            </tr>
                                            <tr>
                                                <td>token</td>
                                                <td>string</td>
                                                <td>是</td>
                                                <td>登录获取的令牌</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            @endif

                            @if(!empty($row->params))
                                <div class="layui-card api-info">
                                    <div class="layui-card-header">参数</div>
                                    <div class="layui-card-body">
                                        <table class="layui-table">
                                            <colgroup>
                                                <col width="150">
                                                <col width="200">
                                                <col>
                                            </colgroup>
                                            <thead>
                                                <tr>
                                                    <th>字段名</th>
                                                    <th>类型</th>
                                                    <th>是否必填</th>
                                                    <th>描述</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($row->params as $param)
                                                <tr>
                                                    <td>{{$param['field']}}</td>
                                                    <td>{{$param['type']}}</td>
                                                    <td>{{$param['required'] ? '必填' : ''}}</td>
                                                    <td>{{$param['des']}}</td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            @endif

                            @if(!empty($row->return_params))
                                <div class="layui-card api-info">
                                    <div class="layui-card-header">反参</div>
                                    <div class="layui-card-body">
                                        <table class="layui-table">
                                            <colgroup>
                                                <col width="150">
                                                <col width="200">
                                                <col>
                                            </colgroup>
                                            <thead>
                                            <tr>
                                                <th>字段名</th>
                                                <th>类型</th>
                                                <th>描述</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($row->return_params as $param)
                                                <tr>
                                                    <td>{{$param['field']}}</td>
                                                    <td>{{$param['type']}}</td>
                                                    <td>{{$param['des']}}</td>
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            @endif
                        </div>

                        <div class="layui-tab-item">
                            <div class="layui-collapse api-info">
                                @if (!empty($row->returns))
                                    @foreach ($row->returns as $return)
                                        <div class="layui-colla-item">
                                            <h2 class="layui-colla-title">{{$return['title']}}</h2>
                                            <div class="layui-colla-content">
                                                <pre class="layui-code" lay-title="json">@json($return['data'], JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)</pre>
                                            </div>
                                        </div>
                                    @endforeach
                                @endif
                            </div>
                        </div>


                        <div class="layui-tab-item">
                            <form class="layui-form" action="" lay-filter="header">
                                @if (!empty($row->headers))
                                    <div class="layui-card api-info">
                                        <div class="layui-card-header">头部</div>
                                        <div class="layui-card-body">
                                            @foreach ($row->headers as $header)
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">{{$header['des']}}:</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="{{$header['field']}}" placeholder="" class="layui-input">
                                                    </div>
                                                </div>
                                            @endforeach
                                        </div>
                                    </div>
                                @endif
                            </form>

                            <form class="layui-form" action="{{$row->route}}" method="{{$row->method}}" lay-filter="api">
                                @if (!empty($row->params))
                                    <div class="layui-card api-info">
                                        <div class="layui-card-header">参数</div>
                                        <div class="layui-card-body">
                                            @foreach ($row->params as $param)
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">{{$param['des']}}:</label>
                                                    <div class="layui-input-block">
                                                        <input type="text" name="{{$param['field']}}" placeholder="" class="layui-input">
                                                    </div>
                                                </div>
                                            @endforeach
                                        </div>
                                    </div>
                                @endif

                                <div class="layui-form-item" style="margin-top: 15px">
                                    <label class="layui-form-label"></label>
                                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="api-send">
                                        <i class="layui-icon layui-icon-search"></i>
                                        请求
                                    </button>

                                    <button type="reset" class="pear-btn pear-btn-md" lay-reset lay-filter="api-send">
                                        <i class="layui-icon layui-icon-refresh"></i>
                                        重置
                                    </button>
                                </div>
                            </form>

                            <div class="layui-card api-info" style="margin-top: 15px">
                                <div class="layui-card-header">返回数据</div>
                                <div class="layui-card-body">
                                    <pre class="layui-code" id="api_data" lay-title="json"></pre>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    </body>
    @parent
@endsection
